/**
 * @file 装饰器包装器
 * @author DuskyHuang 圣子
*/

/** 
 * @param decorator 指定的装饰器类型
 * @param handler 包装器处理函数
 * @return 指定类型(D)装饰器的包装器
*/
export function swapper<decorator extends Decorator>(handler: DecoratorHandler<decorator>): DecoratorSwapper<decorator> {
    return function (arg0: primitive | object, ...rests: any[]): any {
        if (arg0 instanceof Object) {
            return handler([arg0, ...rests] as Parameters<decorator>) as decorator;
        } else {
            return function (...params: Parameters<decorator>) {
                return handler(params, ...[arg0, ...rests]);
            } as unknown as DecoratorFactory<decorator>;
        }
    } as DecoratorSwapper<decorator>;
}